<template>
  <a-card :bordered="false" class="card-area">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col ::sm="{span:24}" :lg="{span:6}">
            <a-form-item label="招生年度">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zsnj">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:24}" :lg="{span:6}">
            <a-form-item label="学习形式">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zhxlxxxs">
                <a-select-option v-for="i in selectMenu.xxlx" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:24}" :lg="{span:6}">
            <span class="table-page-search-submitButtons">
            <a-button type="primary" @click="loadData">查询</a-button>
              <a-button type="primary" @click="exportExcel">导出</a-button>
              </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :pagination="false"
       @change="handleTableChange"
    >
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>
  </a-card>
</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = ['TYPE0311', 'TYPE0312', 'TYPE0126', 'TYPE0075', 'TYPE0056', 'TYPE0083', 'TYPE0125', 'TYPE0072']
export default {
  name: 'Admissionstat',
  components: {
    STable
  },
  data () {
    return {
      loading: false,
      data: [],
      // 查询参数
      queryParam: {
        zhxlxxxs: '',
        zsnj:'',
      },
      postParams: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
         {
          title: '院系代码',
          dataIndex: 'zsyxm'
        },
        {
          title: '院系',
          dataIndex: 'ssyxm'
        },
        {
         title: '计划人数',
         dataIndex: 'jrls'
       },
       {
         title: '录取人数',
         dataIndex: 'lqrs'
       },
       {
         title: '非专业计划数',
         dataIndex: 'fzyrs'
       },
       {
         title: '非专业录取数',
         dataIndex: 'fzyrqls'
       },
       {
         title: '专业计划数',
         dataIndex: 'zykhrs'
       },
       {
         title: '专业录取数',
         dataIndex: 'zylqrs'
       }
      ],

      // custom table alert & rowSelection
      options: {
        alert: { show: false }
      },
      visible: false,
      confirmLoading: false,
      editId: null,
      selectMenu: {
        yx: [], // 院系
        xxlx:[]
      }
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0307: state => state.app['TYPE0307'], // 学习形式
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
            // 获取学习形式
        this.$api.base.dictionaryData('TYPE0441').then(res => {
        	this.selectMenu.xxlx = res.data
        })

         // 获取当前学年
        this.$api.base.getSchoolYear().then(res=>{
          this.queryParam.zsnj = res.data.masterAdmissionYear
           this.loadData({
            pageSize: 10,
            pageNum: 1
          })
        })
      })
    },
    // 选择院系
    yxChange (code) {
      this.$set(this.queryParam, 'zszym', '')
       this.getProssion(code)
    },
    getProssion(code){
      this.$api.base.majorAll({lsdwh: code}).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
    },
    // 加载数据
    loadData (parameter = {}) {
       if(!parameter.pageNum){
        this.pagination.current = 1
        parameter.pageNum = 1
      }
      let params = Object.assign(this.queryParam, parameter)
       this.loading = true;
        this.$api.recruitstat.collegesAdminssionList(params).then(res=>{
             const pagination = { ...this.pagination
            };
            pagination.total = 0
            if (res.data && res.data.total) {
              pagination.total = res.data.total;
            }
            this.data = []
            this.pagination = pagination;
            if (res.data && res.data.length) {
              this.data = res.data;
            }
            this.loading = false;
        })
    },
    // 分页
    handleTableChange (pagination, filters, sorter) {
     console.log(pagination);
     const pager = { ...this.pagination };
     pager.current = pagination.current;
     this.pagination = pager;
     this.loadData({
       pageSize: 10,
       pageNum: pagination.current
     });
    },
    // 导出
    exportExcel () {
      console.log('导出')
      this.$export('admissions/yxlqrstj/export',this.queryParam)
    }
  }
}
</script>
